package com.smarth.zhizulian.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.widget.TextViewCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.smarth.zhizulian.R;

import java.util.List;


/**
 * Created by LV.3 on 2016/12/9.
 */

public class TabPagerAdapter extends FragmentPagerAdapter {
    List<Fragment> fragmentList;
    List<String> titleList;
    int[] iconList;
    Context context;

    public TabPagerAdapter(Context context, FragmentManager fm, List<Fragment> fragmentList, List<String> titleList, int[] iconList) {
        super(fm);
        this.context = context;
        this.fragmentList = fragmentList;
        this.titleList = titleList;
        this.iconList = iconList;
    }


    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titleList.get(position);
    }

    public View getTabView(int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_tab, null);
        ImageView iv_icon = (ImageView) view.findViewById(R.id.iv_icon);
        TextView tv_name = (TextView) view.findViewById(R.id.tv_name);
        iv_icon.setImageResource(iconList[position]);
        tv_name.setText(getPageTitle(position));
        return view;
    }
}
